home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program computes a matrix - vector product, dividing the matrix into
- * rows, with multiple rows per processor. The matrix is of size M x N,
- * where M must be greater than P, but not necessarily a multiple. This
- * program uses methodology and functions provided by the map.c include
- * file. Use of a package along these lines can be helpful when a large
- * number of distributed objects of sizes which are not multiples of the
- * environment structure size are used. */
-
- /* A listing of the map.c file appears immediately after this program. */
-
- #include "dino.h"
-
- #define P 3
- #define M 16
- #define N 9
-
- environment node[P:id] {
-
- #include "../inc/map.c"
-
- /* ==> Includes the map.c include file. Since
- this file contains code, it must be
- included within an environment. */
-
- composite matvec (in a, in x, out y)
- double distributed a[M][N] map BlockRow; /* Input matrix */
- double distributed x[N] map all; /* Input vector */
- double distributed y[M] map Block; /* Result vector */
-
- {
- int i, j; /* Looping variables */
- map_var a1; /* ==> Declares a variable to hold useful
- information about an axis of a
- distributed data structure which
- is [block] mapped. */
-
- /* Setup map_var a1 */
- set_map_var (M, /* Size of the axis */
- P, /* Size of the environment axis it's mapped to */
- id, /* Environment index identifier for that axis */
- 0, /* Left overlap of the mapping function */
- 0, /* Right overlap of the mapping function */
- &a1); /* Address of the map_var */
-
- /* ==> This function, defined in map.c, sets
- up the map_var a1 to contain information
- about the first axis of the distributed
- variable a (which is the same as the
- only axis of x). */
-
- /* Loop thru the rows of a[][] which are on this environment */
- for (i = a1.left; i <= a1.right; i++) {
-
- /* ==> This statement loops thru the correct
- rows of a[][] by using information from
- a1, the map_var set up earlier.
- "a1.left" and "a1.right" refer to the
- first and last elements of the "home"
- data on this environment */
- /* Compute y[i] */
- y[i] = 0;
- for (j = 0; j < N; j++)
- y[i] += a[i][j] * x[j];
- }
- }
- }
-
- environment host {
-
- double a[M][N];
- double x[N];
- double y[M];
-
- void main ()
-
- {
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] and v[] */
- for (j = 0; j < N; j++) {
- x[j] = j;
- for (i = 0; i < M; i++)
- a[i][j] = i + j;
- }
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
-
- printf ("\nInitial data for x:\n");
- for (i = 0; i < N; i++)
- printf ("%6.2f\n", x[i]);
-
- /* Perform the computation */
- matvec (a[][], x[], y[])#;
-
- /* Printout the resulting vector y */
- printf ("\nResult data for y:\n");
- for (i = 0; i < M; i++)
- printf ("%6.2f\n", y[i]);
- }
- }
-